//
//  ViewController.m
//  scrollview
//
//  Created by fgq on 16/6/11.
//  Copyright © 2016年 fgq. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self initSubView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initSubView
{
    UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, 375, 675)];
    
    scrollview.backgroundColor = [UIColor redColor];
    
    self.scrollView = scrollview;
    
    self.scrollView.contentSize = CGSizeMake(375, 675*2);
    
    [self.view addSubview:scrollview];
    
    //配置offset,失效
    self.scrollView.contentOffset = CGPointMake(376, 0);
    
    //配置contentInset,失效
    self.scrollView.contentInset = UIEdgeInsetsMake(675*2, 0, 0, 0);

    //监听scrollview的contentOffset属性
    [self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    if([keyPath isEqualToString:@"contentOffset"])
    {
        NSLog(@"%@", NSStringFromCGPoint(self.scrollView.contentOffset));
    }
}

@end
